package czx.wt.util.ip;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 类作用描述
 * @Author: ChenZhiXiang
 * @CreateDate: 2018/12/19 0019 16:35
 * @Version: 1.0
 */
public class IPUtil {

    public static String getIpAddr(HttpServletRequest request) {
        String ip;
        if (null != request){
            ip = request.getHeader("x-forwarded-for");
            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
                ip = request.getHeader("Proxy-Client-IP");
            }
            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
                ip = request.getHeader("WL-Proxy-Client-IP");
            }
            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
                ip = request.getRemoteAddr();
            }
        } else {
            ip = "0.0.0.0";
        }
        return ip;
    }
}
